const arr = [1,  2,  3,  3, 4, 4, 4, 4 ,4 , 5,  5,  6,  7, 7, 9, 23, 34, 34, 65, 77]

// 普通二分
const binary_search = function(arr, x){
  let head = 0, tail = arr.length - 1, mid;
  while(head <= tail){
    mid = head + ((tail - head) >> 1);
    if(arr[mid] === x) return mid;
    if(arr[mid] < x) { 
      head = mid + 1;
    } else {
      tail = mid - 1;
    }
  }
  return -1;
}
// let result = binary_search(arr, 2);
// console.log(result); 
